package com.ym.medical.service.impl;

import com.ym.medical.domain.vo.DoctorSelfIndexCountVO;
import com.ym.medical.service.ICommonSV;
import com.ym.medical.service.IDoctorDetailsSV;
import com.ym.medical.service.IDoctorSelfSV;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * 医生个人中心相关service
 *
 * @author: 李涛
 * @version: 2019年05月28日 17:23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DoctorSelfSVImpl implements IDoctorSelfSV {

	@Autowired
	private ICommonSV commonSV;

	@Autowired
	private IDoctorDetailsSV doctorDetailsSV;

	@Override
	public DoctorSelfIndexCountVO statisticalSelfData(Long userId) {
		Map<String, Object> params = new HashMap<>();
		String sql = " SELECT" +
				" (" +
				"  select count(1) answerNum " +
				"  from order_flow_record_view ha " +
				"    INNER JOIN inquiry_order hc on hc.id = ha.order_id " +
				"  left join doctor_studio hb on hb.id = ha.doctor_ds_id " +
				"  where ha.STATUS > '03' and  doctor_id = #{params.doctorId} " +
				"  AND ( " +
				"   doctor_order_time BETWEEN DATE_FORMAT( " +
				"    CURDATE(), " +
				"    '%Y-%m-%d %H:%i:%s' " +
				"   ) " +
				"   AND now() " +
				"  ) " +
				" ) AS todayOrder," +
				" (" +
				" SELECT" +
				" count(1) patientEvaluation" +
				" FROM" +
				" comment_record" +
				" WHERE" +
				" comment_appPerson = #{params.doctorId}" +
				" ) AS patientEvaluation," +
				" (select count(0) from mind where pay_state = '02' and doctor_id = #{params.doctorId}) as recommended";
		params.put("doctorId", userId);
		return commonSV.queryEntity(sql, params, DoctorSelfIndexCountVO.class);
	}

}
